﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using jp110311.StorageModels;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace MvcWebRole1
{
    // メモ: IIS6 または IIS7 のクラシック モードの詳細については、
    // http://go.microsoft.com/?LinkId=9394801 を参照してください

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Bbs Index",
                "Bbs/{zipCode}/Index/{page}",
                new { controller = "Bbs", action = "Index", page = 1 });

            routes.MapRoute(
                "Bbs Search",
                "Bbs/{zipCode}/Search/{tag}/{page}",
                new { controller = "Bbs", action = "Search", page = 1 });

            routes.MapRoute(
                "Bbs Add Tag",
                "Bbs/{zipCode}/{BbsMsgId}/AddTag",
                new { controller = "Bbs", action = "AddTag" });

            routes.MapRoute(
                "Bbs Remove Tag",
                "Bbs/{zipCode}/{BbsMsgId}/RemoveTag/{tag}",
                new { controller = "Bbs", action = "RemoveTag" });

            routes.MapRoute(
                "Bbs",
                "Bbs/{zipCode}/{action}",
                new { controller = "Bbs", action = "Index" });

            routes.MapRoute(
                "AddressBook Index",
                "Messaging/AddrBook/{page}",
                new { controller = "Messaging",action="AddrBook", page=1 }
                );

            routes.MapRoute(
                "AddressBook tag address",
                "Messaging/TagAddr/{bookedUser}",
                new { controller = "Messaging", action = "TagAddr" }
                );

            routes.MapRoute(
                "Messageing index",
                "Messaging/Index/{mode}/{page}",
                new
                {
                    controller = "Messaging",
                    action = "Index",
                    mode = "Unread",
                    page = 1
                }
                );

            routes.MapRoute(
                "Message detail",
                "Messaging/Detail/{mode}/{id}",
                new
                {
                    controller = "Messaging",
                    action = "Detail",
                    mode = "Unread"
                });

            routes.MapRoute(
                "Seek next message",
                "Messaging/Next/{mode}/{id}",
                new
                {
                    controller="Messaging",
                    action="Next",
                    markRead = false,
                    markImportance= false
                }
                );

            routes.MapRoute(
                "Seek prev message",
                "Messaging/Prev/{mode}/{id}",
                new
                {
                    controller = "Messaging",
                    action = "Prev",
                    markRead = false,
                    markImportance = false
                }
                );

            routes.MapRoute(
                "Unmark Importance",
                "Messaging/Unmark/{mode}/{id}",
                new
                {
                    controller="Messaging",
                    action = "Unmark"
                }
                );

            routes.MapRoute(
                "Default", // ルート名
                "{controller}/{action}/{id}", // パラメーター付きの URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // パラメーターの既定値
            );

        }

        protected void Application_Start()
        {
            if (RoleEnvironment.IsAvailable)
            {
                CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) =>
                                                                     {
                                                                         var connectionString =
                                                                             RoleEnvironment.
                                                                                 GetConfigurationSettingValue(configName);
                                                                         configSettingPublisher(connectionString);
                                                                     });
            }

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }

    }
}